package com.shitou.dao;

import java.math.BigInteger;

import org.hibernate.SQLQuery;
import org.springframework.stereotype.Repository;

import com.shitou.pojo.Issues;

@Repository
public class IssuesDao extends BaseDao<Issues, Integer> {

	public BigInteger findByTypeAndState(int type, int state, int projectid) {
		StringBuilder sql = new StringBuilder();
		sql.append("SELECT COUNT(i.id) FROM t_issues AS i ");
		sql.append("LEFT JOIN t_issues_assignment AS a ON (i.id = a.issuesid) ");
		sql.append("WHERE TYPE = ? AND state = ? AND projectid = ? ");
		SQLQuery query = getSession().createSQLQuery(sql.toString());
		query.setInteger(0, type);
		query.setInteger(1, state);
		query.setInteger(2, projectid);
		return (BigInteger) query.uniqueResult();
	}
	
	public BigInteger findByTypeAndProjectId(int type, int projectid) {
		String sql = "SELECT COUNT(id) FROM t_issues WHERE TYPE = ? AND projectid = ?";
		SQLQuery query = getSession().createSQLQuery(sql);
		query.setInteger(0, type);
		query.setInteger(1, projectid);
		return  (BigInteger) query.uniqueResult();
	}
}
